<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lzy">
    <title>lzy-</title>
    <style>
        html,body{
            height: 100%;
        }
        body{
            margin: 0;
        }
        main{
            width: 500px;
            height: 200px;
            margin: 200px auto;
            padding: 10px;
            border: 2px solid gray;
        }
        div{
            display: inline-block;
            box-sizing: border-box;
            width: 100px;
            height: 100px;
            float: left;
            border: 1px solid lightgray;
        }
        div>img{
            width: 100%;
            height: 100%;
            opacity: 0.5;
        }
    </style>
</head>
<body>
    <main>
        <div><img src="img/1.jpg" alt=""></div>
        <div><img src="img/2.jpg" alt=""></div>
        <div><img src="img/3.jpg" alt=""></div>
        <div><img src="img/4.jpg" alt=""></div>
        <div><img src="img/5.jpg" alt=""></div>
        <div><img src="img/6.jpg" alt=""></div>
        <div><img src="img/7.jpg" alt=""></div>
        <div><img src="img/8.jpg" alt=""></div>
        <div><img src="img/9.jpg" alt=""></div>
        <div><img src="img/10.jpg" alt=""></div>
    </main>
</body>
</html>
<script>
    var imgs = document.querySelectorAll('img');
    for(var i=0;i<imgs.length;i++){
        imgs[i].index=i;
        imgs[i].onmouseover=function(){
            imgs[this.index].style.opacity='1';
        }
        imgs[i].onmouseout=function(){
            imgs[this.index].style.opacity='0.5';
        }
    }
</script>